package com.ytraveler.conf.transaction;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;

/**
 * @author hyf
 * @version 1.0
 * @date
 */
@Aspect
@Configuration
public class TransactionAdviceConfig {/*
    private static final String AOP_POINTCUT_EXPRESSION = "execution (* com.***.service.*.*(..))";


   @Bean

    @Bean
    public TransactionInterceptor txAdvice(){
        DefaultTransactionAttribute txAttr_REQUIRED = new DefaultTransactionAttribute();
        txAttr_REQUIRED.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

        DefaultTransactionAttribute txAttr_REQUIRED_READONLY = new DefaultTransactionAttribute();
        txAttr_REQUIRED_READONLY.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        txAttr_REQUIRED_READONLY.setReadOnly(true);
        NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
        source.addTransactionalMethod("add*", txAttr_REQUIRED);
        source.addTransactionalMethod("save*", txAttr_REQUIRED);
        source.addTransactionalMethod("delete*", txAttr_REQUIRED);
        source.addTransactionalMethod("update*", txAttr_REQUIRED);
        source.addTransactionalMethod("exec*", txAttr_REQUIRED);
        source.addTransactionalMethod("set*", txAttr_REQUIRED);
        source.addTransactionalMethod("get*", txAttr_REQUIRED_READONLY);
        source.addTransactionalMethod("query*", txAttr_REQUIRED_READONLY);
        source.addTransactionalMethod("find*", txAttr_REQUIRED_READONLY);
        source.addTransactionalMethod("list*", txAttr_REQUIRED_READONLY);
        source.addTransactionalMethod("count*", txAttr_REQUIRED_READONLY);
        source.addTransactionalMethod("is*", txAttr_REQUIRED_READONLY);
        return new TransactionInterceptor(, source);
    }
    @Bean
    public Advisor txAdviceAdvisor(){
        AspectJExpressionPointcut pointcut=new AspectJExpressionPointcut();
        pointcut.setExpression(AOP_POINTCUT_EXPRESSION);
        return new DefaultPointcutAdvisor(pointcut,txAdvice());
    }
*/}
/**
 * 一般三种方式:
 *    1. DataSource
 *    2. TransactionManager和代理机制三部分。
 *
 * 关于当前的源码分析的基本分析:
 *spring支持的7中事务传播行为:
 *  在类TransactionDefinition中声明了数据库传播的
 *  PROPAGATION_REQUIRED:如果不存在，创建一个新的事务.
 *  PROPAGATION_SUPPORTS: 支持一个当前事务，如果当前事务不存在，执行非事务性质的事务。
 *  PROPAGATION_MANDATORY:
 *  PROPAGATION_REQUIRES_NEW:
 *  PROPAGATION_NOT_SUPPORTED:
 *  PROPAGATION_NEVER:
 *  PROPAGATION_NESTED:
 *  在类TransactionDefinition中声明了数据库的隔离级别:
 *    ISOLATION_DEFAULT:
 *    ISOLATION_READ_UNCOMMITTED:
 *    ISOLATION_READ_COMMITTED:
 *    ISOLATION_REPEATABLE_READ:
 *    ISOLATION_SERIALIZABLE:
 *PlatformTransactionManager对事务进行管理的事务管理器：
 *
 *DefaultTransactionAttribute:spring的通用事务属性实现，类配置spring的通用事务属性
 *
 *
 * */